﻿namespace LeetCodeProject._0001_1000._001_100._51_60._053;

public class Solution
{
    public int MaxSubArray(int[] nums)
    {
        if (nums == null || nums.Length == 0)
            throw new ArgumentException();
        var max = nums[0];
        var pre = nums[0];
        for (int i = 1; i < nums.Length; i++)
        {
            pre = Math.Max(pre + nums[i], nums[i]);
            max = Math.Max(max, pre);
        }

        return max;
    }
}